package com.ang.redisson.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RedssonConfig {
    @Autowired
    private RedissonPropertis propertis;

    @Bean
    public RedissonClient redisson() throws IOException {
        Config config = new Config();
        //单机版
        config.useSingleServer()
                .setAddress(propertis.getAddress());
//                .setPassword(propertis.getPassword());

        //添加主从配置
        //config.useMasterSlaveServers().setMasterAddress("").setPassword("").addSlaveAddress(new String[]{"",""});

        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }

}
